<?php


namespace app\admin\controller;


use app\admin\model\Admin\AdminModel;
use app\Utils\Util;
use think\Request;

class Login extends BaseController
{

    /**
     * 登录
     * @param Request $request
     * @return array
     */
    public function login(Request $request)
    {
        $param = $request->param();
        $where = [
            ['account','=',$param['account']]
        ];
        $admin = AdminModel::getAdminWhere($where);
        if($admin){
            $flag = md5($param['password']) == $admin['password'] ? true : false;
            if($flag){
                //$data = checkToken('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIhQCMkJSomIiwiYXVkIjoiIiwiaWF0IjoxNTk3ODA0NjI1LCJuYmYiOjE1OTc4MDQ2MjgsImV4cCI6MTU5NzgwNDYzNSwiZGF0YSI6eyJ1aWQiOjF9fQ.tbnczFtUpirVGVS9zAHd9IgVylHExwxViPJaDYwLK6s');
                $token = signToken($admin['id']);
                return Util::returnJson(self::CODE_SUCCESS,['access_token' => $token],"登录成功");
            }else{
                return Util::returnJson(self::CODE_ERROR,null,"账户或密码错误");
            }
        }else{
            return Util::returnJson(self::CODE_ERROR,null,"账户或密码错误");
        }
    }

}